﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Core
{
    public static class RuleFinder
    {
        public static IRule[] FindAllRules()
        {
            //Use reflection to locate all classes implementing IRule interface
            var allRules = from t in Assembly.GetExecutingAssembly().GetTypes()
                           where t.GetInterfaces().Contains(typeof(IRule)) && t.GetConstructor(Type.EmptyTypes) != null
                           select Activator.CreateInstance(t) as IRule;

            List<IRule> ruleArray = new List<IRule>();

            foreach (var ruleInstance in allRules)
            {
                ruleArray.Add(ruleInstance);
            }

            return ruleArray.ToArray();
        }
    }
}
